package element.ast;

import intermediate_representation.ExpRP;
import table.InterCodeTable;

public class UopNode extends AstNode {
    private String op;
    private AstNode sonNode;

    public UopNode(String op, AstNode sonNode) {
        this.op = op;
        this.sonNode = sonNode;
    }

    @Override
    public String tointerRP() {
        String son = sonNode.tointerRP();
        if (son.charAt(0) == '$') {
            int sonr = Integer.parseInt(son.substring(4));
            InterCodeTable.regindex = sonr;
        }
        InterCodeTable.pushvar();
        ExpRP expRP = new ExpRP(son, op, InterCodeTable.nowVar);
        InterCodeTable.addCode(expRP);
        return InterCodeTable.nowVar;
    }

    @Override
    public void tofuncRP() {
        sonNode.tofuncRP();
    }
}
